package com.zprmb.udzt.adapter;

import java.util.List;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.zprmb.udzt.R;
import com.zprmb.udzt.bean.Address;

public class Address_adapter extends BaseAdapter {
	private List<Address> list;
	private Context context;
	

	public Address_adapter(List<Address> list, Context context) {
		super();
		this.list = list;
		this.context = context;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		Help h=null;
		if(convertView==null){
			h=new Help();
			convertView=LayoutInflater.from(context).inflate(R.layout.address_item, null);
			h.img_default=(ImageView)convertView.findViewById(R.id.img_default);
			h.tv_address=(TextView)convertView.findViewById(R.id.address);
			h.tv_name=(TextView)convertView.findViewById(R.id.name);
			h.li_all=(LinearLayout)convertView.findViewById(R.id.li_all);
			h.tv_tel=(TextView)convertView.findViewById(R.id.tel);
			convertView.setTag(h);
			
		}else{
			h=(Help) convertView.getTag();
		}
		if(list.get(position).isDefault()){
			h.img_default.setVisibility(View.VISIBLE);
			h.li_all.setBackgroundColor(Color.parseColor("#5d6b85"));
			h.tv_address.setTextColor(Color.parseColor("#ffffff"));
			h.tv_name.setTextColor(Color.parseColor("#ffffff"));
			h.tv_tel.setTextColor(Color.parseColor("#ffffff"));
		}else{
			h.img_default.setVisibility(View.GONE);
			h.tv_address.setTextColor(Color.parseColor("#666666"));
			h.tv_address.setTextColor(Color.parseColor("#333333"));
			h.tv_address.setTextColor(Color.parseColor("#333333"));
			h.li_all.setBackgroundColor(Color.parseColor("#ffffff"));
		}
		h.tv_name.setText(list.get(position).getReceiveName());
		h.tv_tel.setText(list.get(position).getReceivePhone());
		if(list.get(position).getProvince().equals(list.get(position).getCity())){
			h.tv_address.setText(list.get(position).getProvince()+list.get(position).getArea()+list.get(position).getExpressAddr());
		}else{
			
	
		h.tv_address.setText(list.get(position).getProvince()+list.get(position).getCity()+list.get(position).getArea()+list.get(position).getExpressAddr());
		}
		return convertView;
	}
	private class Help{
		private TextView tv_name,tv_tel,tv_address;
		private ImageView img_default;
		private LinearLayout li_all;
	}

}
